﻿using System.ComponentModel;
using System.Modules.Utility.DTO.ULS.Monitoring;

namespace System.Modules.Utility.DTO.ULS
{
    class LogEntryViewModel : INotifyPropertyChanged
    {
        #region Field Names
        public enum FiedNames
        {
            Bookmarked
        } 
        #endregion

        #region Fields
        readonly LogEntry _entry;
        bool _bookmarked; 
        #endregion

        #region INotifyPropertyChanged Members
        public event PropertyChangedEventHandler PropertyChanged = delegate { };
        #endregion

        #region Constructor
        public LogEntryViewModel(LogEntry entry)
        {
            _entry = entry;
        } 
        #endregion

        #region Properties
        public bool Bookmarked
        {
            get { return _bookmarked; }
            set
            {
                _bookmarked = value;
                OnPropertyChanged(FiedNames.Bookmarked);
            }
        }
        public string Timestamp
        {
            get { return _entry.Timestamp; }
            set
            {
                _entry.Timestamp = value;
                OnPropertyChanged(LogEntry.FieldNames.Timestamp);
            }
        }
        public string Process
        {
            get { return _entry.Process; }
            set
            {
                _entry.Process = value;
                OnPropertyChanged(LogEntry.FieldNames.Process);
            }
        }
        public string TID
        {
            get { return _entry.TID; }
            set
            {
                _entry.TID = value;
                OnPropertyChanged(LogEntry.FieldNames.TID);
            }
        }
        public string Area
        {
            get { return _entry.Area; }
            set
            {
                _entry.Area = value;
                OnPropertyChanged(LogEntry.FieldNames.Area);
            }
        }
        public string Category
        {
            get { return _entry.Category; }
            set
            {
                _entry.Category = value;
                OnPropertyChanged(LogEntry.FieldNames.Category);
            }
        }
        public string EventID
        {
            get { return _entry.EventID; }
            set
            {
                _entry.EventID = value;
                OnPropertyChanged(LogEntry.FieldNames.EventID);
            }
        }
        public string Level
        {
            get { return _entry.Level; }
            set
            {
                _entry.Level = value;
                OnPropertyChanged(LogEntry.FieldNames.Level);
            }
        }
        public string Message
        {
            get { return _entry.Message; }
            set
            {
                _entry.Message = value;
                OnPropertyChanged(LogEntry.FieldNames.Message);
            }
        }
        public string Correlation
        {
            get { return _entry.Correlation; }
            set
            {
                _entry.Correlation = value;
                OnPropertyChanged(LogEntry.FieldNames.Correlation);
            }
        } 
        #endregion

        #region Methods
        void OnPropertyChanged(Enum propertyName)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName.ToString()));
        } 
        #endregion

        #region Implicit Operators
        public static implicit operator LogEntry(LogEntryViewModel entryViewModel)
        {
            return entryViewModel._entry;
        }

        public static implicit operator LogEntryViewModel(LogEntry entry)
        {
            return new LogEntryViewModel(entry);
        } 
        #endregion
    }
}
